#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2019/3/1 9:27 AM
# @Author  : Mr.Dynasty
# @File    : test1.py
# @Software: PyCharm
# @license : Copyright(C), Mr.Dynasty
#文件目录统计
import os,sys



def calculate(path):
    size = 0
    if os.path.isdir(path):
        #是文件夹 遍历文件夹
        files = os.listdir(path)
        for file in files:
            file_path = os.path.join(path, file)
            size += calculate(file_path)
    elif os.path.isfile(path):
        #是文件 直接返回大小
         size += os.path.getsize(path)
    else:
        size += 0
    return size

if __name__ == '__main__':
    #命令行中输入路径参数
    if len(sys.argv) != 2:
        print('请输入正确的路径参数')
    else:
        path = sys.argv[1]
        print('文件大小为{}'.format(calculate(path)))
